/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package canteen.sys.model.entity.repository;

import canteen.sys.model.entity.BillDetail;
import canteen.sys.model.generic.GenericHibernateDAOSupport;
import java.util.List;
import javax.swing.JOptionPane;
import org.hibernate.HibernateException;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author TNT
 */
public class BillDetailDAOImpl extends GenericHibernateDAOSupport<BillDetail, Long> implements BillDetailDAO {

    @Override
    public List<BillDetail> findAllBillDetailByBillId(int billId) {
        List<BillDetail> listBillDetails = null;
        Transaction transaction = getSession().beginTransaction();
        try {
            listBillDetails = getSession().createCriteria(BillDetail.class)
                    .add(Restrictions.eq("bill.bId", billId)).list();
            transaction.commit();
        } catch (HibernateException ex) {
            transaction.rollback();
            JOptionPane.showMessageDialog(null, "Error:\n" + ex.getMessage());
        }
        return listBillDetails;
    }
}
